package com.ruoyi.system.controller.qihuo;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.QihuoDict;
import com.ruoyi.system.service.IQihuoDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 期货字典Controller
 *
 * @author ruoyi
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/qihuo/dict")
public class QihuoDictController extends BaseController
{
    @Autowired
    private IQihuoDictService qihuoDictService;

    /**
     * 查询期货字典列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QihuoDict qihuoDict)
    {
        startPage();
        List<QihuoDict> list = qihuoDictService.selectQihuoDictList(qihuoDict);
        return getDataTable(list);
    }

    /**
     * 导出期货字典列表
     */
    @Log(title = "期货字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QihuoDict qihuoDict)
    {
        List<QihuoDict> list = qihuoDictService.selectQihuoDictList(qihuoDict);
        ExcelUtil<QihuoDict> util = new ExcelUtil<QihuoDict>(QihuoDict.class);
        util.exportExcel(response, list, "期货字典数据");
    }

    /**
     * 获取期货字典详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(qihuoDictService.selectQihuoDictById(id));
    }

    /**
     * 新增期货字典
     */
    @Log(title = "期货字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QihuoDict qihuoDict)
    {
        return toAjax(qihuoDictService.insertQihuoDict(qihuoDict));
    }

    /**
     * 修改期货字典
     */
    @Log(title = "期货字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QihuoDict qihuoDict)
    {
        return toAjax(qihuoDictService.updateQihuoDict(qihuoDict));
    }

    /**
     * 删除期货字典
     */
    @Log(title = "期货字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qihuoDictService.deleteQihuoDictByIds(ids));
    }
}
